<template>
<div>
    <Table :columns="columns" :data="passwordsArray"></Table>
</div>

</template>

<script>
export default {
  props: {
    passwords: Object,
    roomId: Number
  },
  data () {
    return {
      passwordsArray: [],
      passwordEnd: '',
      columns: [
        {
          title: '密码编号',
          key: 'id',
          align: 'center',
          minWidth: 90,
          render: (h, params) => {
            const result = params.row.id
            return h('span', null, result)
          }
        },
        {
          title: '密码有效期',
          key: 'operation',
          align: 'center',
          minWidth: 280,
          render: (h, params) => {
            let begin = new Date(params.row.permission.begin * 1000).Format('yyyy-MM-DD HH:mm')
            let end = new Date(params.row.permission.end * 1000).Format('yyyy-MM-DD HH:mm')
            return h('span', null, begin + ' - ' + end)
          }
        },
        {
          title: '发送给',
          key: 'name',
          align: 'center',
          minWidth: 100,
          render: (h, params) => {
            return h('span', null, params.row.name)
          }
        },
        {
          title: '应用门锁',
          key: 'send_to',
          align: 'center',
          minWidth: 120,
          render: (h, params) => {
            let result = this.roomId === params.row.room_id ? '内门' : '外门'
            return h('span', null, result)
          }
        }
      ]
    }
  },
  created () {
    this.transferPasswordsArray()
  },
  methods: {
    transferPasswordsArray () {
      const result = []
      for (let item in this.passwords) {
        result.push({
          ...this.passwords[item],
          room_id: item
        })
      }
      this.passwordsArray = result
    }
  }
}
</script>
